<?php 
	echo $this->inlineScript()->setScript('$(document).ready(function(){
		$("#from").datepicker({ dateFormat: "yy-mm-dd" });
		$("#to").datepicker({ dateFormat: "yy-mm-dd" });
	})');
?>
<form id="formrap" method="post" action="">
	<table cellspacing="1" cellpadding="6" class="tlist">
		<tr>
			<td>
				Od: <?php echo $this->formText( 'from', $this->from ); ?>
			</td>
			<td>
				Do: <?php echo $this->formText( 'to', $this->to ); ?>
			</td>
			<td>
				<a onclick="$('#formrap').submit()" class="button" href="javascript::void(null)">
					<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/plus_16.png);" class="inb">Generuj raport prowizji</div>
				</a>
			</td>
		</tr>
	</table>
</form>
<div class="bglist">
	<div class="bglistq">
	
	<?php if( $this->raportList ) { ?>
		
		<?php if( count( $this->raportList ) ) { ?>
			
			<table cellspacing="1" cellpadding="6" class="tlist">
				<tr>
					<th>Nr. transakcji</th>
					<th>Klient</th>
					<th>Data</th>
					<th>Kwota prowizji</th>
				</tr>
				<?php 
				$sum = 0;
				foreach( $this->raportList as $item ) { ?>
				<tr>
					<td><?php echo $item['o_id'] ?></td>
					<td><?php 
					echo $item['Users']['name'] . ' ' . $item['Users']['surname'] . '<br />';
					echo $item['Users']['email'] 
					?></td>
					<td><?php echo $item['add_date'] ?></td>
					<td><?php 
						$provision = ( $item['price'] * $item['provision'] ) / 100;
						$sum = $sum + number_format( $provision, 2, '.', '' );
						echo number_format( $provision, 2, '.', ' ' ) . ' ' . $item['currency'];
					?></td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="4" style="text-align:right;">Łączna kwota prowizji: <b><?php echo number_format( $sum, 2, '.', ' ' ) . ' ' . $item['currency']; ?></b></td>
				</tr>
			</table>
		<?php } else { ?>
			<table cellspacing="1" cellpadding="6" class="tlist">
				<tr>
					<th>Nr. transakcji</th>
					<th>Klient</th>
					<th>Data</th>
					<th>Kwota prowizji</th>
				</tr>
				<tr>
					<td colspan="4">brak rekordów spełniajacych kryteria</td>
				</tr>
			</table>
		<?php } ?>
	<?php } else { ?>
		<table cellspacing="1" cellpadding="6" class="tlist">
			<tr>
				<th>Id</th>
				<th>User</th>
				<th>Zaproszenie wysłano</th>
				<th>Odpowiedział rejestracją</th>
			</tr>
			<?php foreach( $this->list as $item ) { ?>
			<tr>
				<td><?php echo $item['i_id'] ?></td>
				<td><?php echo $item['email'] ?></td>
				<td><?php echo $item['add_date'] ?></td>
				<td><?php 
					$userTable = Doctrine_Core::getTable('Users');
					$el = $userTable->findOneByEmail( $item['email'] );
					if( $el ) {
						echo 'Tak, dnia: ' . $el->registration_date;
					} else {
						echo 'Nie';
					}
				?></td>
			</tr>
			<?php } ?>
		</table>
	<?php } ?>
	</div>
</div>
<?php 
if( !$this->raportList ) {
	echo $this->render('global/pager.phtml'); 
}
?>